package com.huisang.controller;


import com.github.pagehelper.PageInfo;
import com.huisang.domain.Customer;
import com.huisang.domain.Track;
import com.huisang.domain.TrackVo;
import com.huisang.service.TrackService;
import com.huisang.util.ResponseEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class TrackController {
    @Autowired
    private TrackService trackService;

    /**
     * 添加意向
     * @param track
     * @return
     */
    @PostMapping("/tra")
    public ResponseEntity<Integer> addTrack(Track track){
        int i = trackService.addTrack(track);
        ResponseEntity<Integer> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMessage("OK");
        responseEntity.setData(i);
        return responseEntity;
    }

    /**
     * 删除意向
     * @param tid
     * @return
     */
    @DeleteMapping("/tra/{tid}")
    public ResponseEntity<Integer> deleteTrack(@PathVariable(value = "tid") int tid){
        int i = trackService.deleteTrack(tid);
        ResponseEntity<Integer> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMessage("OK");
        responseEntity.setData(i);
        return responseEntity;
    }

    /**
     * 修改意向
     */
    @PutMapping("/tra")
    public ResponseEntity<Integer> updateTrack(Track track){
        int i = trackService.updateTrack(track);
        ResponseEntity<Integer> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMessage("OK");
        responseEntity.setData(i);
        return responseEntity;
    }

    /**
     * 查找所有意向
     */
    @GetMapping("/tra")
    public ResponseEntity<PageInfo<TrackVo>> findAllTrack(int pageNum, int pageSize){
        PageInfo<TrackVo> allTrack = trackService.findAllTrack(pageNum, pageSize);
        ResponseEntity<PageInfo<TrackVo>> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMessage("OK");
        responseEntity.setData(allTrack);
        return responseEntity;
    }

    /**
     * 查找单个意向
     */
    @GetMapping("/tra/{tid}")
    public ResponseEntity<Track> findOneTrack(@PathVariable(value = "tid")int tid){
        Track oneTrack = trackService.findOneTrack(tid);
        ResponseEntity<Track> responseEntity = new ResponseEntity<>();
        responseEntity.setCode(200);
        responseEntity.setMessage("OK");
        responseEntity.setData(oneTrack);
        return responseEntity;
    }

}
